<?php
namespace Pw\MainBundle\Classes;
class VideoTag extends Tag
{
	public function __construct(){
		parent::__construct('video', null, null, false);
	}
	public function isParamAllowed($param, $value){
		if ($param === 'source') {
			return true;
		}
		return false;
	}
	public function getRepalceOpen() {
		$res = '';
		if (isset($this->params['source'])) {
			$match = array();
			if (preg_match('/http(s)?:\/\/www.youtube.com\/(watch\?v=|embed\/)(?<id>[a-zA-Z0-9_-]+)/', $this->params['source'] , $match)) {
				$res .= '<iframe width="640" height="360" src="http://www.youtube.com/embed/' . $match['id'] . '" frameborder="0" allowfullscreen></iframe>';
			}			
		}
		return $res;
	}
	public function getRepalceClose() {
		return '';
	}
}
